package com.lmiot.xyclick.Share;

import android.app.Dialog;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.lmiot.xyclick.App.MyApp;
import com.lkx.liandianqinew.R;
import com.lmiot.xyclick.Share.Bean.SearchMsgBeanRes;
import com.lmiot.xyclick.Share.inteface.OnMsgListener;
import com.lmiot.xyclick.Util.ClickUtils;
import com.lmiot.xyclick.Util.DataUtil;
import com.lmiot.xyclick.Util.DebugUtli;
import com.lmiot.xyclick.Util.DpUtil;
import com.lmiot.xyclick.Util.EditDialogUtil;
import com.lmiot.xyclick.Util.LayoutDialogUtil;
import com.lmiot.xyclick.Util.LogUtil;
import com.lmiot.xyclick.Util.MathUtils;
import com.lmiot.xyclick.Util.PhoneUtil;
import com.lmiot.xyclick.inteface.OnBasicListener;
import com.xiaoyi.intentsdklibrary.Bean.MsgBean;
import com.xiaoyi.intentsdklibrary.Bean.MsgBeanSqlUtil;
import com.xiaoyi.intentsdklibrary.Bean.ShareBean;
import com.youyi.yychosesdk.utils.file.FileUtils;
import com.youyi.yyviewsdklibrary.Dialog.util.ToastUtil;
import com.youyi.yyviewsdklibrary.View.roundedimageview.RoundedImageView;
import java.io.File;
import java.util.List;

public class ShareAdapter extends RecyclerView.Adapter {
    private static final String TAG = "ShareAdapter";
    private Context mContext;
    private Dialog mDialog;
    private List<ShareBean> mList;
    private String mSearchName;
    private final boolean mShowDel;

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public int getItemViewType(int i) {
        return 0;
    }

    public void setSearchName(String str) {
        this.mSearchName = str;
        notifyDataSetChanged();
    }

    public ShareAdapter(Context context, List<ShareBean> list, boolean z) {
        this.mContext = context;
        this.mList = list;
        this.mShowDel = z;
    }

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        return new MyViewHolder(View.inflate(this.mContext, R.layout.item_share, null));
    }

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int i) {
        MyViewHolder myViewHolder = (MyViewHolder) viewHolder;
        final ShareBean shareBean = this.mList.get(i);
        if (this.mShowDel) {
            myViewHolder.delBt.setVisibility(View.VISIBLE);
            myViewHolder.delBt.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass1 */

                public void onClick(View view) {
                    LayoutDialogUtil.showSureDialog(ShareAdapter.this.mContext, "温馨提示", "您是否要删除名称为：" + shareBean.getScript_name() + "的自动化？", true, true, "取消", "确定", new LayoutDialogUtil.OnResultClickListener() {
                        /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass1.AnonymousClass1 */

                        @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
                        public void result(boolean z) {
                            if (z) {
                                ShareAdapter.this.delMethod(shareBean);
                            }
                        }
                    });
                }
            });
        } else {
            myViewHolder.delBt.setVisibility(View.GONE);
        }
        File file = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp", shareBean.getScript_type_id() + ".jpg");
        if (file.exists()) {
            myViewHolder.autoIcon.setImageBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()));
            myViewHolder.bg.setVisibility(View.GONE);
            myViewHolder.img.setVisibility(View.GONE);
            myViewHolder.autoIcon.setVisibility(View.VISIBLE);
        } else {
            myViewHolder.bg.setVisibility(View.VISIBLE);
            myViewHolder.img.setVisibility(View.VISIBLE);
            myViewHolder.autoIcon.setVisibility(View.GONE);
            Glide.with(this.mContext).load(Integer.valueOf((int) R.drawable.play_auto_blue)).into(myViewHolder.autoIcon);
            int i2 = i % 5;
            if (i2 == 4) {
                myViewHolder.bg.setBackgroundResource(R.drawable.auto_color_other);
            } else if (i2 == 3) {
                myViewHolder.bg.setBackgroundResource(R.drawable.auto_color_play);
            } else if (i2 == 2) {
                myViewHolder.bg.setBackgroundResource(R.drawable.auto_color_time);
            } else if (i2 == 1) {
                myViewHolder.bg.setBackgroundResource(R.drawable.auto_color_screen);
            } else {
                myViewHolder.bg.setBackgroundResource(R.drawable.auto_color_text);
            }
        }
        String script_name = shareBean.getScript_name();
        if (TextUtils.isEmpty(this.mSearchName)) {
            myViewHolder.name.setText(script_name);
            if (shareBean.getChecked_flag()) {
                myViewHolder.name.setText(script_name);
            } else {
                myViewHolder.name.setText(Html.fromHtml(("(审核中)" + script_name).replace("(审核中)", "<font color='#FF0000'>(审核中)</font>")));
            }
        } else {
            myViewHolder.name.setText(Html.fromHtml(script_name.replace(this.mSearchName, "<font color='#FF0000'>" + this.mSearchName + "</font>")));
        }
        myViewHolder.actionNum.setText("动作：" + shareBean.getScript_action_sum());
        myViewHolder.fileSize.setText("大小：" + shareBean.getScript_size());
        String phone_size = shareBean.getPhone_size();
        String[] split = phone_size.split("#");
        if (split.length == 4) {
            try {
                myViewHolder.phoneSize.setText("适配：" + split[2] + "*" + split[3]);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            myViewHolder.phoneSize.setText("适配：" + phone_size);
        }
        myViewHolder.typeName.setText("类型：" + ShareSDK.getInstance().getTypeName(shareBean.getScript_type_code()));
        myViewHolder.msgText.setText(shareBean.getGrade_num() + "");
        if (shareBean.getAccount_id().equals(PhoneUtil.getIMEI(MyApp.getContext()))) {
            myViewHolder.userName.setText(Html.fromHtml("作者：我".replace("我", "<font color='#FF0000'>我</font>")));
        } else {
            myViewHolder.userName.setText("作者：" + ShareSDK.getInstance().getUserName(shareBean.getAccount_id()));
        }
        myViewHolder.updateTime.setText("更新：" + shareBean.getDate().replace("T", ""));
        myViewHolder.detail.setText("简介：" + shareBean.getScript_note());
        myViewHolder.pointText.setText(shareBean.getNeed_acc_point() + "积分");
        myViewHolder.pointText.setOnLongClickListener(new View.OnLongClickListener() {
            /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass2 */

            public boolean onLongClick(View view) {
                EditDialogUtil.getInstance().edit(ShareAdapter.this.mContext, 1, "请输入", "", "", new EditDialogUtil.EditMethod() {
                    /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass2.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.Util.EditDialogUtil.EditMethod
                    public void edit(String str) {
                        if (str.equals("123")) {
                            ShareSDK.getInstance().delFile(shareBean.getScript_id(), new OnBasicListener() {
                                /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass2.AnonymousClass1.AnonymousClass1 */

                                @Override // com.lmiot.xyclick.inteface.OnBasicListener
                                public void result(boolean z, String str) {
                                }
                            });
                        }
                    }
                }, false);
                return true;
            }
        });
        if (!TextUtils.isEmpty(shareBean.getUser_scene())) {
            myViewHolder.lockText.setText(Html.fromHtml("已加密".replace("已加密", "<font color='#FF0000'>已加密</font>")));
        } else {
            myViewHolder.lockText.setText("未加密");
        }
        myViewHolder.downText.setText(shareBean.getDown_sum() + "下载");
        myViewHolder.downBt.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass3 */

            public void onClick(View view) {
                ShareSDK.getInstance().downShare(ShareAdapter.this.mContext, shareBean, new OnBasicListener() {
                    /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass3.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.inteface.OnBasicListener
                    public void result(boolean z, String str) {
                    }
                });
            }
        });
        myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass4 */

            public void onClick(View view) {
                ShareAdapter.this.showDataDialog(shareBean);
            }
        });
        myViewHolder.msgLayout.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass5 */

            public void onClick(View view) {
                ShareAdapter.this.showMsg(shareBean.getScript_id());
            }
        });
        myViewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
            /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass6 */

            public boolean onLongClick(View view) {
                if (!DebugUtli.isDebugVersion(MyApp.getContext())) {
                    return true;
                }
                ShareSDK.getInstance().delFile(shareBean.getScript_id(), new OnBasicListener() {
                    /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass6.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.inteface.OnBasicListener
                    public void result(boolean z, String str) {
                        if (z) {
                            ShareAdapter.this.mList.remove(i);
                            ShareAdapter.this.notifyDataSetChanged();
                        }
                    }
                });
                return true;
            }
        });
    }

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public int getItemCount() {
        List<ShareBean> list = this.mList;
        if (list == null) {
            return 0;
        }
        return list.size();
    }

    public void setData(List<ShareBean> list, String str) {
        this.mList = list;
        this.mSearchName = str;
        notifyDataSetChanged();
    }

    private class MyViewHolder extends RecyclerView.ViewHolder {
        TextView actionNum;
        RoundedImageView autoIcon;
        ImageView bg;
        TextView delBt;
        TextView detail;
        TextView downBt;
        TextView downText;
        TextView fileSize;
        ImageView img;
        TextView lockText;
        LinearLayout msgLayout;
        TextView msgText;
        TextView name;
        TextView phoneSize;
        TextView pointText;
        TextView startText;
        TextView typeName;
        TextView updateTime;
        TextView userName;

        public MyViewHolder(View view) {
            super(view);
            this.bg = (ImageView) view.findViewById(R.id.cb_bg);
            this.img = (ImageView) view.findViewById(R.id.id_img);
            this.autoIcon = (RoundedImageView) view.findViewById(R.id.auto_icon);
            this.name = (TextView) view.findViewById(R.id.id_name);
            this.actionNum = (TextView) view.findViewById(R.id.id_acton_sum);
            this.fileSize = (TextView) view.findViewById(R.id.id_file_size);
            this.phoneSize = (TextView) view.findViewById(R.id.id_phone_size);
            this.typeName = (TextView) view.findViewById(R.id.id_type);
            this.userName = (TextView) view.findViewById(R.id.id_user);
            this.updateTime = (TextView) view.findViewById(R.id.id_time);
            this.detail = (TextView) view.findViewById(R.id.id_detail);
            this.downBt = (TextView) view.findViewById(R.id.id_down);
            this.delBt = (TextView) view.findViewById(R.id.id_del);
            this.pointText = (TextView) view.findViewById(R.id.id_point);
            this.lockText = (TextView) view.findViewById(R.id.id_lock_text);
            this.downText = (TextView) view.findViewById(R.id.id_down_num);
            this.startText = (TextView) view.findViewById(R.id.id_start_text);
            this.msgText = (TextView) view.findViewById(R.id.id_msg_text);
            this.msgLayout = (LinearLayout) view.findViewById(R.id.id_msg_layout);
        }
    }

    private void delShareFile(String str) {
        try {
            File file = new File(Environment.getExternalStorageDirectory() + "/XYclick/data", str + "." + DataUtil.FILE_XYCLICK_DATA);
            if (file.exists()) {
                file.delete();
            }
            File file2 = new File(Environment.getExternalStorageDirectory() + "/XYclick/temp", str + "." + DataUtil.FILE_AUTO_DATA);
            if (file2.exists()) {
                file2.delete();
            }
            File file3 = new File(Environment.getExternalStorageDirectory() + "/XYclick/temp", str + "." + DataUtil.FILE_ACTION_DATA);
            if (file3.exists()) {
                file3.delete();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showDataDialog(final ShareBean shareBean) {
        Dialog dialog = this.mDialog;
        if (dialog != null && dialog.isShowing()) {
            this.mDialog.dismiss();
        }
        Dialog createBottomDailog = LayoutDialogUtil.createBottomDailog(this.mContext, R.layout.dialog_show_share);
        this.mDialog = createBottomDailog;
        ImageView imageView = (ImageView) createBottomDailog.findViewById(R.id.cb_bg);
        ImageView imageView2 = (ImageView) this.mDialog.findViewById(R.id.id_img);
        RoundedImageView roundedImageView = (RoundedImageView) this.mDialog.findViewById(R.id.auto_icon);
        TextView textView = (TextView) this.mDialog.findViewById(R.id.id_action_num);
        TextView textView2 = (TextView) this.mDialog.findViewById(R.id.id_fen);
        TextView textView3 = (TextView) this.mDialog.findViewById(R.id.id_password);
        TextView textView4 = (TextView) this.mDialog.findViewById(R.id.id_detail);
        TextView textView5 = (TextView) this.mDialog.findViewById(R.id.tv_cancel);
        TextView textView6 = (TextView) this.mDialog.findViewById(R.id.tv_sure);
        ((TextView) this.mDialog.findViewById(R.id.id_name)).setText(shareBean.getScript_name());
        ((TextView) this.mDialog.findViewById(R.id.id_user)).setText("分享者：" + ShareSDK.getInstance().getUserName(shareBean.getAccount_id()));
        if (!TextUtils.isEmpty(shareBean.getUser_scene())) {
            textView3.setText("是否加密：是");
        } else {
            textView3.setText("是否加密：否");
        }
        textView4.setText("自动化简介：" + shareBean.getScript_note());
        int need_acc_point = shareBean.getNeed_acc_point();
        textView2.setText("下载积分：" + need_acc_point + "积分");
        textView.setText("动作数量：" + shareBean.getScript_action_sum() + "个");
        textView6.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass7 */

            public void onClick(View view) {
                ShareAdapter.this.mDialog.dismiss();
                ShareSDK.getInstance().downShare(ShareAdapter.this.mContext, shareBean, new OnBasicListener() {
                    /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass7.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.inteface.OnBasicListener
                    public void result(boolean z, String str) {
                    }
                });
            }
        });
        textView5.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass8 */

            public void onClick(View view) {
                ShareAdapter.this.mDialog.dismiss();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showMsg(final String str) {
        ShareSDK.getInstance().searchMsg(str, new OnMsgListener() {
            /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass9 */

            @Override // com.lmiot.xyclick.Share.inteface.OnMsgListener
            public void result(List<SearchMsgBeanRes.BodyBean.DataBean.GradeListBean> list) {
                if (list != null && list.size() > 0) {
                    for (SearchMsgBeanRes.BodyBean.DataBean.GradeListBean gradeListBean : list) {
                        MsgBeanSqlUtil.getInstance().add(new MsgBean(null, gradeListBean.getGrade_id(), gradeListBean.getScript_id(), gradeListBean.getAccount_id(), gradeListBean.getGrade_level(), gradeListBean.getGrade_content(), gradeListBean.isChecked_flag(), gradeListBean.getDate(), gradeListBean.getRemark()));
                    }
                }
                ShareAdapter.this.showScriptMsgDialog(str);
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showScriptMsgDialog(final String str) {
        Dialog dialog = this.mDialog;
        if (dialog != null && dialog.isShowing()) {
            this.mDialog.dismiss();
        }
        Dialog createDailog = LayoutDialogUtil.createDailog(this.mContext, R.layout.dialog_msglist);
        this.mDialog = createDailog;
        createDailog.setCancelable(true);
        ImageView imageView = (ImageView) this.mDialog.findViewById(R.id.id_close);
        ListView listView = (ListView) this.mDialog.findViewById(R.id.id_listivew);
        final RatingBar ratingBar = (RatingBar) this.mDialog.findViewById(R.id.id_ratingbar);
        final EditText editText = (EditText) this.mDialog.findViewById(R.id.id_edit);
        TextView textView = (TextView) this.mDialog.findViewById(R.id.id_send);
        List<MsgBean> searchByScriptID = MsgBeanSqlUtil.getInstance().searchByScriptID(str);
        LogUtil.d("ShareFragmentDetail", "msgBeanList.size():" + searchByScriptID.size());
        if (searchByScriptID.size() > 5) {
            listView.setLayoutParams(new LinearLayout.LayoutParams(-1, DpUtil.dip2px(MyApp.getContext(), 400.0f)));
        } else {
            listView.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
        }
        listView.setAdapter((ListAdapter) new MsgAdapter(searchByScriptID));
        textView.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass10 */

            public void onClick(View view) {
                String obj = editText.getText().toString();
                if (TextUtils.isEmpty(obj)) {
                    ClickUtils.onlyVibrate(MyApp.getContext());
                    ToastUtil.warning("内容不能为空！");
                    return;
                }
                ShareAdapter.this.mDialog.dismiss();
                int rating = (int) ratingBar.getRating();
                if (rating < 1) {
                    rating = 1;
                }
                ShareSDK.getInstance().addMsg(PhoneUtil.getIMEI(MyApp.getContext()), str, rating > 5 ? 5 : rating, obj, "", new OnBasicListener() {
                    /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass10.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.inteface.OnBasicListener
                    public void result(boolean z, String str) {
                        ToastUtil.success("评价成功！");
                    }
                });
            }
        });
        imageView.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass11 */

            public void onClick(View view) {
                ShareAdapter.this.mDialog.dismiss();
            }
        });
    }

    /* access modifiers changed from: private */
    public class MsgAdapter extends BaseAdapter {
        List<MsgBean> mList;

        public Object getItem(int i) {
            return null;
        }

        public long getItemId(int i) {
            return 0;
        }

        public MsgAdapter(List<MsgBean> list) {
            this.mList = list;
        }

        public int getCount() {
            return this.mList.size();
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            View inflate = View.inflate(ShareAdapter.this.mContext, R.layout.item_msg, null);
            RatingBar ratingBar = (RatingBar) inflate.findViewById(R.id.id_start);
            MsgBean msgBean = this.mList.get(i);
            ((TextView) inflate.findViewById(R.id.id_user)).setText("用户：" + ShareSDK.getInstance().getUserName(msgBean.getAccount_id()));
            ((TextView) inflate.findViewById(R.id.id_time)).setText(msgBean.getDate().replace("T", ""));
            ((TextView) inflate.findViewById(R.id.id_msg)).setText(msgBean.getGrade_content());
            try {
                ratingBar.setRating((float) MathUtils.parseInt(msgBean.getGrade_level()));
            } catch (Exception e) {
                e.printStackTrace();
            }
            return inflate;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void delMethod(final ShareBean shareBean) {
        ShareSDK.getInstance().delFile(shareBean.getScript_id(), new OnBasicListener() {
            /* class com.lmiot.xyclick.Share.ShareAdapter.AnonymousClass12 */

            @Override // com.lmiot.xyclick.inteface.OnBasicListener
            public void result(boolean z, String str) {
                if (z) {
                    ShareAdapter.this.mList.remove(shareBean);
                    ShareAdapter.this.notifyDataSetChanged();
                }
            }
        });
    }
}
